var path = require("path");
var fs = require("fs");
var count=0;
const dir=path.parse(__dirname).dir+"/log/";
Log={record:function (logInfo){
           var date = new Date();
           var filename=dir+date.getFullYear()+"-"+date.getMonth()+"-"+date.getDay()+"-"+count+".log";
           //判断文件是否存在
           fs.access(filename,(err)=>{
               if(err){
                  fs.mkdirSync(filename,null);
                   count++;
               }else {
                   fs.stat(filename,function (error,stats) {
                       if(error){
                           logInfo+=error.message;
                       }
                       if(stats.size>3*1024*1024){
                           count++;
                           filename=dir+date.getFullYear()+"-"+date.getMonth()+"-"+date.getDay()+"-"+count+".log";
                           fs.mkdirSync(filename);
                       }
                   });
               }
           });
           //记录日志
        fs.appendFile(filename,logInfo+"\n",function (err){
            if(err){
                console.log(err);
            }
        });
    },
}
Log.record("获取订单...");



